# Contributor: Abdó Roig-Maranges <abdo.roig@gmail.com>

_realname=git-lfs
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.4.1
pkgsrc=${_realname}-${pkgver}
pkgrel=1
arch=("any")
pkgdesc="An open source Git extension for versioning large files (mingw-w64)"
url="https://git-lfs.github.com/"
license=('MIT')
options=('!strip')
depends=("git")
#makedepends=("unzip" "${MINGW_PACKAGE_PREFIX}-go" "${MINGW_PACKAGE_PREFIX}-ruby")
makedepends=("unzip" "patch" "${MINGW_PACKAGE_PREFIX}-go")

source=(${pkgsrc}.zip::"https://github.com/github/git-lfs/archive/v${pkgver}.zip"
        "0001-Translate-git-paths-from-msys-to-windows.patch")

# Extract sources ourselves (avoid bsdtar failure in pull #2406)
noextract=(${pkgsrc}.zip)

sha256sums=('5d9a92a392d7af29f00e83466f14cd1dd8152df6c19d1dd22d9cb09effc36fe3'
            '2a979f08d86197c6946f6cafff34bd7c4b662c4a5562c56d9436dfd6074345c1')

prepare() {
  # Extract sources ourselves (avoid bsdtar failure in pull #2406)
  [[ -d ${srcdir}/${pkgsrc} ]] && rm -rf ${srcdir}/${pkgsrc}
  unzip ${srcdir}/${pkgsrc}.zip -d ${srcdir}

  # apply patches
  cd "${srcdir}/${pkgsrc}"
  patch -N -p1 -i "$srcdir/0001-Translate-git-paths-from-msys-to-windows.patch"

  # Clear go cache
  rm -Rf "$srcdir/src"

  # Setup local gopath
  mkdir -p "$srcdir/src/github.com/git-lfs"
  cp -R "$srcdir/${pkgsrc}/" "$srcdir/src/github.com/git-lfs/git-lfs"

  # Fetch dependencies
  . ${MINGW_PREFIX}/etc/profile.d/go.sh
  GOPATH="$srcdir" go get -v -d

  #gem install ronn
}

build() {
  cd "${srcdir}/${pkgsrc}"

  # build
  . ${MINGW_PREFIX}/etc/profile.d/go.sh
  GOPATH="$srcdir" go run script/*.go -cmd build

  # The man pages need ronn, which needs a bunch of missing ruby dependencies.
  #ronn docs/man/*.ronn
}

package() {
  cd "${srcdir}/${pkgsrc}"
  install -Dm755 "bin/git-lfs" "${pkgdir}${MINGW_PREFIX}/bin/git-lfs"

  # man page
  #install -d "${pkgdir}${MINGW_PREFIX}/share/man/man1"
  #install -Dm644 docs/man/*.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1"
}

